package com.gsafety.wellsfort.domain.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.gsafety.wellsfort.common.enums.CustomerTypeEnum;
import com.gsafety.wellsfort.common.enums.QuestionTypeEnum;
import com.gsafety.wellsfort.domain.model.knowledge.AnswerOption;
import com.gsafety.wellsfort.domain.model.knowledge.Question;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
@ApiModel(value = "试题")
public class QuestionVO {
    @ApiModelProperty(value = "题目id")
    private Integer id;
    @ApiModelProperty(value = "试题对象数值")
    private Integer objectType;
    @ApiModelProperty(value = "试题对象名称")
    private String objectTypeText;
    @ApiModelProperty(value = "试题关键字")
    private String keyword;
    @ApiModelProperty(value = "试题类型数值")
    private Integer examType;
    @ApiModelProperty(value = "试题类型名称")
    private String questionTypeText;
    @ApiModelProperty(value = "试题标题")
    private String title;
    @ApiModelProperty(value = "试题分数")
    private BigDecimal score;
    @ApiModelProperty(value = "更新人")
    private String modifyName;
    @ApiModelProperty(value = "作业题目关系ID",required = false)
    private Integer workQuestionRelId;
    @ApiModelProperty(value = "考试题目关系ID",required = false)
    private Integer examQuestionRelId;
    @ApiModelProperty(value = "考试题目序号",required = false)
    private Integer serialNum;
    /**
     * 创建时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    /**
     * 修改时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "修改时间")
    private Date updateTime;
    @ApiModelProperty(value = "创建人")
    private Integer creator;
    @ApiModelProperty(value = "操作人")
    private Integer operator;

    @ApiModelProperty(value = "答案解析")
    private String analyzing;

    private List<AnswerOption> answerOptionList;

    public static  class POBuilder{
        Question q =new Question();
        QuestionVO qVo;
        public POBuilder(QuestionVO qVo){
            this.qVo=qVo;
        }
        public Question build(){
            BeanUtils.copyProperties(qVo,q);
            q.setExamType(qVo.examType);
            q.setTitle(qVo.title);
            return q;
        }
    }
    public static  class VOBuilder{
        Question q ;
        QuestionVO qVo=new QuestionVO();
        public VOBuilder(Question q){
            this.q=q;
        }
        public QuestionVO build(){
            BeanUtils.copyProperties(q,qVo);
            qVo.setExamType(q.getExamType());
            qVo.setTitle(q.getTitle());
            qVo.setObjectTypeText(qVo.getObjectType()!=null?CustomerTypeEnum.parseVal(qVo.getObjectType()).label:"");
            qVo.setQuestionTypeText(qVo.getObjectType()!=null?QuestionTypeEnum.parseVal(qVo.getExamType()).label:"");
            return qVo;
        }
    }
}
